package com.example.ljw.paperlive.ui.famliy;

import android.util.Log;

import com.example.ljw.paperlive.bean.FamliyBean;

import java.util.Map;

import rx.Scheduler;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by LJW on 2016/11/24.
 */

public class FamliyPresenter implements FamliyContract.IFamliyPresenter{
    private FamliyContract.IFamliyModel iFamliyModel=null;
    private FamliyContract.IFamliyView iFamliyView=null;
    public FamliyPresenter(FamliyContract.IFamliyView iFamliyView) {
        iFamliyModel=new FamliyModle();
        this.iFamliyView=iFamliyView;

    }
    @Override
    public void getFamliyData(Map<String, String> map) {
        iFamliyModel.getFamliyData(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FamliyBean>() {
                    @Override
                    public void onStart() {
                        super.onStart();
                        iFamliyView.showProgressBar();
                    }

                    @Override
                    public void onCompleted() {
                    iFamliyView.hideProgressBar();
                    }

                    @Override
                    public void onError(Throwable e) {
                       iFamliyView.error(e);
                    }

                    @Override
                    public void onNext(FamliyBean famliyBean) {
                        iFamliyView.getFamliyData(famliyBean);
                    }
                });
    }


}
